package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller  //这里直接远程调用的item方法所以不用再次转json
public class ItemController {
    @Autowired
    private ItemFeignClient itemFeignClient;

    @RequestMapping("{skuId}.html")
    public String getItem(@PathVariable Long skuId,Model model){
        //通过skuId查询skuInfo
        Result<Map> result = itemFeignClient.getItem(skuId);
        //数据保存！
        model.addAllAttributes(result.getData()); //ItemApiController中return.Result.ok(map) ok中包数据map给了data
        //返回模板名称
//        return "item/index";
        return "item/item";
    }


}
